package com.ruoyi.sale.service.Impl;


import com.ruoyi.common.core.constant.SaleConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.sale.domain.Sale;
import com.ruoyi.sale.mapper.SaleMapper;
import com.ruoyi.sale.service.ISaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SaleServiceImpl implements ISaleService {
    @Autowired
    private SaleMapper saleMapper;
    @Override
    public boolean checkSaleNameUnique(Sale sale) {
        Long saleId = StringUtils.isNull(sale.getSaleId()) ? -1 : sale.getSaleId();
        Sale saleFound = saleMapper.checkSaleNameUnique(sale);
        if(StringUtils.isNotNull(saleFound) && saleFound.getSaleId().longValue() != saleId.longValue()){
            return SaleConstants.NOT_UNIQUE;
        }
        return SaleConstants.UNIQUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSale(Sale sale) {
        return  saleMapper.insertSale(sale);

    }

    @Override
    public List<Sale> selectSaleList(Sale sale) {
        return saleMapper.selectSaleList(sale);
    }

    @Override
    public List<Sale> selectSaleList1() {
        return saleMapper.selectSaleList1();
    }

    @Override
    public int deleteSaleById(Long saleId) {
        return saleMapper.deleteSaleById(saleId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateSale(Sale sale) {
        return saleMapper.updateSale(sale);
    }

    @Override
    public Sale selectSaleById(Long saleId) {
        return saleMapper.selectSaleById(saleId);
    }

}
